package com.zk.mockito.cases;

import org.junit.Assert;
import org.junit.Test;

import java.util.List;

import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

/**
 * Stubbing Void Methods
 * 存根 空返回值方法
 * but you may prefer to use these methods in place of the alternative with when(), for all of your stubbing calls.
 * Read more about these methods:
 *
 * doReturn(Object)
 *
 * doThrow(Throwable...)
 *
 * doThrow(Class)
 *
 * doAnswer(Answer)
 *
 * doNothing()
 *
 * doCallRealMethod()
 */
public class Case012_StubbingVoidMethods {

    @Test
    public void testStubbingVoidMethods() {
        List mockedList = mock(List.class);
        doThrow(new RuntimeException()).when(mockedList).clear();

        //following throws RuntimeException:
        Assert.assertThrows(RuntimeException.class, () -> mockedList.clear());
    }
}
